using Coding4Fun.Phone.Controls.Helpers;
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Shapes;
namespace Coding4Fun.Phone.Controls
{
	public class ColorSlider : ColorBaseControl
	{
		private const double double_0 = 24.0;
		private const string string_0 = "Body";
		private const string string_1 = "SelectedColor";
		private const string string_2 = "Slider";
		private bool bool_0;
		protected Grid Body;
		protected Rectangle SelectedColor;
		protected SuperSlider Slider;
		public static readonly DependencyProperty ThumbProperty = DependencyProperty.Register("Thumb", typeof(object), typeof(ColorSlider), new PropertyMetadata(null));
		public static readonly DependencyProperty IsColorVisibleProperty = DependencyProperty.Register("IsColorVisible", typeof(bool), typeof(ColorSlider), new PropertyMetadata(true, new PropertyChangedCallback(ColorSlider.OnIsColorVisibleChanged)));
		public static readonly DependencyProperty OrientationProperty = DependencyProperty.Register("Orientation", typeof(Orientation), typeof(ColorSlider), new PropertyMetadata(0, new PropertyChangedCallback(ColorSlider.smethod_0)));
		public object Thumb
		{
			get
			{
				return base.GetValue(ColorSlider.ThumbProperty);
			}
			set
			{
				base.SetValue(ColorSlider.ThumbProperty, value);
			}
		}
		public bool IsColorVisible
		{
			get
			{
				return (bool)base.GetValue(ColorSlider.IsColorVisibleProperty);
			}
			set
			{
				base.SetValue(ColorSlider.IsColorVisibleProperty, value);
			}
		}
		public Orientation Orientation
		{
			get
			{
				return (Orientation)base.GetValue(ColorSlider.OrientationProperty);
			}
			set
			{
				base.SetValue(ColorSlider.OrientationProperty, value);
			}
		}
		public ColorSlider()
		{
			base.set_DefaultStyleKey(typeof(ColorSlider));
			base.add_IsEnabledChanged(new DependencyPropertyChangedEventHandler(this.ColorSlider_IsEnabledChanged));
			base.add_Loaded(new RoutedEventHandler(this.ColorSlider_Loaded));
		}
		private void ColorSlider_Loaded(object sender, RoutedEventArgs e)
		{
			this.method_3();
		}
		public override void OnApplyTemplate()
		{
			base.OnApplyTemplate();
			this.Body = (base.GetTemplateChild("Body") as Grid);
			this.Slider = (base.GetTemplateChild("Slider") as SuperSlider);
			if (this.Thumb == null)
			{
				this.Thumb = new ColorSliderThumb();
			}
			this.SelectedColor = (base.GetTemplateChild("SelectedColor") as Rectangle);
			base.add_SizeChanged(new SizeChangedEventHandler(this.ColorSlider_SizeChanged));
			if (this.Slider != null)
			{
				this.Slider.ValueChanged += new RoutedPropertyChangedEventHandler<double>(this.method_0);
				if (base.Color.get_A() == 0 && base.Color.get_R() == 0 && base.Color.get_G() == 0 && base.Color.get_B() == 0)
				{
					base.Color = Color.FromArgb(255, 6, 255, 0);
					return;
				}
				this.UpdateLayoutBasedOnColor();
			}
		}
		private void method_0(object sender, RoutedPropertyChangedEventArgs<double> e)
		{
			this.method_1(e.get_NewValue());
		}
		private void method_1(double double_1)
		{
			this.bool_0 = true;
			base.ColorChanging(ColorSpace.GetColorFromHueValue((float)((int)double_1 % 360)));
			this.bool_0 = false;
		}
		private void ColorSlider_SizeChanged(object sender, SizeChangedEventArgs e)
		{
			this.method_2();
		}
		private void ColorSlider_IsEnabledChanged(object sender, DependencyPropertyChangedEventArgs e)
		{
			this.method_3();
		}
		private static void OnIsColorVisibleChanged(DependencyObject dependencyObject_0, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs_0)
		{
			ColorSlider colorSlider = dependencyObject_0 as ColorSlider;
			if (colorSlider != null)
			{
				colorSlider.method_2();
			}
		}
		private static void smethod_0(DependencyObject dependencyObject_0, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs_0)
		{
			ColorSlider colorSlider = dependencyObject_0 as ColorSlider;
			if (colorSlider != null)
			{
				colorSlider.method_2();
			}
		}
		private void method_2()
		{
			if (this.Body != null && this.Slider != null && this.SelectedColor != null)
			{
				bool flag = this.Orientation == 0;
				this.Slider.set_Background(base.get_IsEnabled() ? ColorSpace.GetColorGradientBrush(this.Orientation) : ColorSpace.GetBlackAndWhiteGradientBrush(this.Orientation));
				this.Body.get_RowDefinitions().Clear();
				this.Body.get_ColumnDefinitions().Clear();
				if (flag)
				{
					this.Body.get_RowDefinitions().Add(new RowDefinition());
					this.Body.get_RowDefinitions().Add(new RowDefinition());
				}
				else
				{
					this.Body.get_ColumnDefinitions().Add(new ColumnDefinition());
					this.Body.get_ColumnDefinitions().Add(new ColumnDefinition());
				}
				FrameworkElement frameworkElement = (FrameworkElement)this.Slider.Thumb;
				if (frameworkElement != null)
				{
					frameworkElement.set_Height(flag ? 24.0 : double.NaN);
					frameworkElement.set_Width(flag ? double.NaN : 24.0);
				}
				this.SelectedColor.SetValue(Grid.RowProperty, flag ? 1 : 0);
				this.SelectedColor.SetValue(Grid.ColumnProperty, flag ? 0 : 1);
				double actualWidth = this.Slider.get_ActualWidth();
				double actualHeight = this.Slider.get_ActualHeight();
				double num = flag ? actualWidth : actualHeight;
				FrameworkElement arg_18E_0 = this.SelectedColor;
				double height;
				this.SelectedColor.set_Width(height = num);
				arg_18E_0.set_Height(height);
				if (flag)
				{
					this.Body.get_RowDefinitions().get_Item(0).set_Height(new GridLength(1.0, 2));
					this.Body.get_RowDefinitions().get_Item(1).set_Height(new GridLength(1.0, 0));
				}
				else
				{
					this.Body.get_ColumnDefinitions().get_Item(0).set_Width(new GridLength(1.0, 2));
					this.Body.get_ColumnDefinitions().get_Item(1).set_Width(new GridLength(1.0, 0));
				}
				this.SelectedColor.set_Visibility(this.IsColorVisible ? 0 : 1);
				return;
			}
		}
		protected internal override void UpdateLayoutBasedOnColor()
		{
			if (this.bool_0)
			{
				return;
			}
			base.UpdateLayoutBasedOnColor();
			if (this.Slider != null)
			{
				this.Slider.Value = (double)base.Color.GetHue();
			}
		}
		private void method_3()
		{
			VisualStateManager.GoToState(this, base.get_IsEnabled() ? "Normal" : "Disabled", true);
		}
	}
}
